<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
$return=array();
if($_RQ['op']=='edit'){
	$item1=$this->plugin_setting('secury');
	$item2=$this->plugin_setting('basic');
	$hdps =array(
		array('title'=>'首页','picurl'=>'../addons/jy_goodserpfw/resource/images/hdp01.jpg'),
	);
    $return['item']=array_merge($item1,$item2);
	$return['item']['hdps'] = !empty($return['item']['hdps']) ? $return['item']['hdps'] : $hdps;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'参数设置',
		'edit_tab' =>'参数设置',
		'edits'=>array(
			array('title' => '基本设置',
				'list' => array(
					array('title'=>'[温馨提示]：<red>点击扫码无效？微信公众号没设置好，是唤醒不了扫码功能的！</red>','type'=>'tip'),
					array('name'=>'name','title'=>'公司名称','type'=>'string'),
					array('name'=>'logo','title'=>'公司logo','type'=>'image'),
					array('type'=>'text','title'=>'公司简介','name'=>'content'),
					array('name'=>'mobile','title'=>'联系方式','type'=>'string'),	
					array('name'=>'address','title'=>'公司地址','type'=>'string'),
					array('name'=>'curl','title'=>'公司网址','type'=>'string'),
					array('name'=>'isjian','title'=>'简化展示','type'=>'switch'),
				),
			),
			array('title' => '防伪码生成设置',
				'list' => array(
				array('type'=>'tip','title'=>'[温馨提示]：如果已经生成了已经添加了防伪商品，添加防伪批次，请勿修改本：防伪码生成设置。否则可能导致，已生成的批次不可用！'),
				array('name'=>'xpre','title'=>'箱标签前缀','type'=>'string','help'=>'例如 XW'),
				array('name'=>'pre','title'=>'小标签前缀','type'=>'string','help'=>'例如 FW'),
				array('name'=>'goods','title'=>'商品编号位数','type'=>'radio','options'=>'num','help'=>'不填默认10位'),
				array('name'=>'batch','title'=>'批号位数','type'=>'radio','options'=>'num','help'=>'不填默认10位'),
				array('name'=>'serial','title'=>'流水号位数','type'=>'string','type'=>'radio','options'=>'num','help'=>'不填默认10位'),
				array('name'=>'code','title'=>'校验码位数','type'=>'string','help'=>'建议10位以内'),	
				array('name'=>'garble','title'=>'混淆码位数','type'=>'string','help'=>'建议5位以内'),
				array('name'=>'num','title'=>'查询次数限制','type'=>'string','help'=>'限制每个防伪码允许查询次数，0表示不限制'),
				array('name'=>'mima','title'=>'操作密码','type'=>'string'),
			),
			),
			array(
				'title'=>'幻灯片',
					'list'=>array(
						array(
							'type'=>'array',
							'name'=>'hdps',
							'add_tip'=>'添加一个幻灯片',
								'list'=>array(
									array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片'),
									array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
									
								),
								'details'=>array(
									array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片','help'=>''),
									array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
									
								)
						)
					)
			),
			
		)
		);
	$return['num']=array('4'=>'4位','6'=>'6位','8'=>'8位','10'=>'10位');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if($postdata['code']>32 || $postdata['code']<4){
		exi('校验码位数不能大于32,小于4','error');
	}
	if($postdata['garble']>32 || $postdata['garble']<4){
		exi('混淆码位数不能大于32,小于4','error');
	}
	$this->plugin_setting('basic',$postdata);
	$data=array_fields(array('xpre','pre','goods','batch','serial','code','garble','num'),$postdata);
	$secury=$this->plugin_setting('secury');
	if($data['pre']!=$secury['pre'] || $data['goods']!=$secury['goods'] || $data['batch']!=$secury['batch'] || $data['serial']!=$secury['serial'] || $data['code']!=$secury['code'] || $data['garble']!=$secury['garble']){
		$ischange=true;
	}
	if($ischange){
		$isgoods=pdo_get('jy_goodserpfw_goods',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid']),'id');
		$isbatch=pdo_get('jy_goodserpfw_batch',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid']),'id');
		if($isgoods['id'] && $isbatch['id']){
			//exi('修改《防伪码生成设置》失败，请先删除原所有防伪商品，防伪批次！','error');
		}
		//exi('你已修改了《防伪码生成设置》，原所有防伪商品，防伪批次将失效！');
	}
	$this->plugin_setting('secury',$data);
	exi('设置成功');
}
?>